<?php
/**
 * 
 * @author natanael
 *
 *Modelo de provicia Real
 *
 */
 class mprovincia2 extends Model{

         private $mTableName = "GN_Provincia";
 	 
 	 function __construct(){
 	 	       parent::Model();
 	 	       $this->load->database();
 	 }
 	 
 	  function LoadCompaniaById($id_compania) 
	  {
		  $qresult = $this->db->get_where($this->mTableName,array('id' => $id_compania));		
		  if ($qresult->num_rows() == 0)
		  {
			 return false;
		  }	

			return new mpro($qresult->row());
	 }
	 
       function LoadProvincias($name = false, $pais = false, $start = false, $offset = false, $sortname = false, $sortorder = false) {
			if($name != false && $name != '')
				$this->db->like('descricion', $name);
			
			if($pais != false && $pais != '')
				$this->db->where('IdPais',$pais);

			if($offset != false)
				$this->db->limit($offset, $start);

			if($sortname != false && $sortorder != false) {
				$this->db->order_by($sortname, $sortorder);
			}

			$result = $this->db->get_where($this->mTableName);

			return $this->GetProvinciasArrayFromQueryResult($result);
		}
		
 	function GetCount() {
			return count($this->LoadProvincias());
		}

  function GetProvinciasArrayFromQueryResult($result) {
			if ($result->num_rows() == 0)
				return false;

			$provincias_arr = array();

			foreach ($result->result() as $record) {
				$provincias_arr[] = new mpro($record);
			}

			return $provincias_arr;
    	}
		
 	 
 
 	 
 }

class mpro{
  	    
  	    private $idOrden = 0;
  	    private $descricion = "";
  	  
  	    
  	    function __construct($ojt){
  	    	    
  	    	      $this->setId($ojt->id);
  	    	      $this->setDescriccion($ojt->descricion);
  	    
  	    	
  	    }
  	    
  	    
  	    //id de la orden
  	    public function setId($id){
  	    	$this->idOrden = $id;
  	    }
  	    
  	    public function getId(){
  	    	return $this->idOrden;
  	    }
  	    
  	    //descriccion de la orden
  	    public function setDescriccion($oj){
  	    	$this->descricion = $oj;
  	    }
  	    
  	    public function getDescriccion(){
  	    	return $this->descricion;
  	    }
  	    
  	   
  	
  }

?>